package com.ad.backstage.common.interceptor;


import com.ad.payload.model.CurrentUser;

import javax.servlet.http.HttpServletRequest;

/**
 * @ Description   :  用户信息
 * @ Author        :  dxgong
 * @ CreateDate    :  5/26/2020 4:48 PM
 * @ UpdateDate    :  5/26/2020 4:48 PM
 * @ UpdateRemark  :
 * @ Version       :  1.0
 */
public class RequestHolder {
    private static final ThreadLocal<CurrentUser> userHolder = new ThreadLocal<CurrentUser>();

    private static final ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal<>();

    public static void add(HttpServletRequest request){
        requestHolder.set(request);
    }

    public static CurrentUser getCurrentUser(){
        return userHolder.get();
    }

    public static void setCurrentUser(CurrentUser sysUser){
        userHolder.set(sysUser);
    }

    public static HttpServletRequest getCurrentRequest(){
        return requestHolder.get();
    }

    public static void remove(){
        userHolder.remove();
        requestHolder.remove();
    }

}
